package it.xiuxian.personcenter.activity

import android.text.Editable
import android.text.TextUtils
import android.widget.EditText
import android.widget.LinearLayout
import android.widget.Toast
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import it.xiuxian.lib.base.App
import it.xiuxian.lib.base.ArouterAddress
import it.xiuxian.lib.base.BaseActivity
import it.xiuxian.lib.bean.NewPersonBean
import it.xiuxian.lib.utils.DensityUtil
import it.xiuxian.lib.utils.EditTextFilter
import it.xiuxian.lib.utils.LiveDataBus
import it.xiuxian.lib.utils.RxBusCode
import it.xiuxian.personcenter.R
import it.xiuxian.personcenter.bean.GongXianBean
import it.xiuxian.personcenter.databinding.ActivityMyDataBinding
import it.xiuxian.personcenter.presenter.MyDatumActivityPresenter

@Route(path = ArouterAddress.MYDATUMACTIVITY)
class MyDatumActivity:BaseActivity<MyDatumActivityPresenter>() {
    @JvmField
    @Autowired
    var phone:String? = null
    @JvmField
    @Autowired
    var nickname:String? = null
    @JvmField
    @Autowired
    var qianming:String? = null
   lateinit var binding: ActivityMyDataBinding
    override val layoutId: Int
        get() = R.layout.activity_my_data
    override val presenter: MyDatumActivityPresenter
        get() = MyDatumActivityPresenter()

    override fun initView() {
        setTitle("个人资料")
        ARouter.getInstance().inject(this)
       binding =  getViewDataBinding<ActivityMyDataBinding>()
        binding.include.rightTv.text ="保存"
        EditTextFilter.setEditTextInhibitInputSpaChat(binding.etNick)
        (binding.include.re.layoutParams as LinearLayout.LayoutParams).setMargins(0,
            DensityUtil.getStatusPix(App.INSTANCE.applicationContext)+5,0,0)
    }

    override fun initData() {
        mPresenter!!.getHomePage()
    }

    override fun initEvent() {
        binding.include.rightTv.setOnClickListener {
            mPresenter!!.submit(binding.etQianming.text.toString(),binding.etNick.text.toString())
        }
    }
    fun setdata(msg: String) {
        //Toast.makeText(this,msg, Toast.LENGTH_SHORT).show()
        LiveDataBus.get().with(RxBusCode.FACE).postValue(1357)
        finish()

    }

    fun setUI(data: NewPersonBean){
        binding.tvPhone.text = data.userphone
        binding.etNick.text = Editable.Factory.getInstance().newEditable(data.nickname)
       // binding.etNick.setSelection(data.nickname.length)
        binding.etQianming.text = Editable.Factory.getInstance().newEditable(data.qianming)
       // binding.etQianming.setSelection(data.qianming.length)
    }
}